import {
  customeracceptalterslideorder,
  customerrejectalterslideorder,
  customeracceptalterconfirmorder,
  customerrejectalterconfirmorder,
  customeracceptalterpremium,
  customerrejectalterpremium
} from "@/api/order/modifyGoods";
import quotationDict from "@/dict/quotation";

export const btnModifyGoods = [
  // 买家审批修改商品
  // 点价
  {
    name: "同意修改商品",
    clickEvent: "buyerAcceptPricingModifyGoods",
    flag: "buyerAcceptPricingModifyGoods"
  },
  {
    name: "拒绝修改商品",
    clickEvent: "buyerRejectPricingModifyGoods",
    flag: "buyerRejectPricingModifyGoods"
  },
  {
    name: "同意修改升贴水",
    clickEvent: "buyerAcceptPricingModifyPremium",
    flag: "buyerAcceptPricingModifyPremium"
  },
  {
    name: "拒绝修改升贴水",
    clickEvent: "buyerRejectPricingModifyPremium",
    flag: "buyerRejectPricingModifyPremium"
  },
  // 确定价
  {
    name: "同意修改商品",
    clickEvent: "buyerAcceptConfirmModifyGoods",
    flag: "buyerAcceptConfirmModifyGoods"
  },
  {
    name: "拒绝修改商品",
    clickEvent: "buyerRejectConfirmModifyGoods",
    flag: "buyerRejectConfirmModifyGoods"
  }
];

export const modifyGoods = {
  methods: {
    // 买家同意修改点价升贴水
    buyerAcceptPricingModifyPremium(row) {
      customeracceptalterpremium({
        orderId: row.id,
        version: row.version
      }).then(res => {
        this.$message.success("操作成功");
        this.$emit("handleSuccess", {
          data: res,
          type: "buyerAcceptPricingModifyPremium"
        });
      });
    },
    // 买家拒绝修改点价升贴水
    buyerRejectPricingModifyPremium(row) {
      customerrejectalterpremium({
        orderId: row.id,
        version: row.version
      }).then(res => {
        this.$message.success("操作成功");
        this.$emit("handleSuccess", {
          data: res,
          type: "buyerRejectPricingModifyPremium"
        });
      });
    },
    // 买家同意修改点价商品
    buyerAcceptPricingModifyGoods(row) {
      this.buyerAcceptModifyGoods(row);
    },
    // 买家同意修改确定价商品
    buyerAcceptConfirmModifyGoods(row) {
      this.buyerAcceptModifyGoods(row);
    },
    // 同意修改商品
    buyerAcceptModifyGoods(data) {
      let request =
        data.priceType === quotationDict.priceType.pricing.value
          ? customeracceptalterslideorder
          : customeracceptalterconfirmorder;
      request({
        orderId: data.id,
        version: data.version
      }).then(res => {
        this.$message.success("操作成功");
        this.$emit("handleSuccess", {
          data: res,
          type:
            data.priceType === quotationDict.priceType.pricing.value
              ? "buyerAcceptPricingModifyGoods"
              : "buyerAcceptConfirmModifyGoods"
        });
      });
    },
    // 买家拒绝修改点价商品
    buyerRejectPricingModifyGoods(row) {
      this.buyerRejectModifyGoods(row);
    },
    // 买家拒绝修改点价商品
    buyerRejectConfirmModifyGoods(row) {
      this.buyerRejectModifyGoods(row);
    },
    // 拒绝修改商品
    buyerRejectModifyGoods(data) {
      let request =
        data.priceType === quotationDict.priceType.pricing.value
          ? customerrejectalterslideorder
          : customerrejectalterconfirmorder;
      request({
        orderId: data.id,
        version: data.version
      }).then(res => {
        this.$message.success("操作成功");
        this.$emit("handleSuccess", {
          data: res,
          type:
            data.priceType === quotationDict.priceType.pricing.value
              ? "buyerRejectPricingModifyGoods"
              : "buyerRejectConfirmModifyGoods"
        });
      });
    }
  }
};
